<%--
  User: dw
  Date: 2019/12/16
  Time: 23:13
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>测评</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
</head>
<body>
  <div class="layui-card" style="width: 60%;margin: auto 20%">
    <div class="layui-card-header" style="text-align: center;font-size: 20px;margin-bottom: 2%;background-color: #009688;color:#f0f0f0;font-weight: bold"
    >开始测评</div>
    <div class="layui-card layui-form" lay-filter="component-form-element">
      <div class="layui-card-header">请选择测评对象</div>
      <div class="layui-card-body layui-row layui-col-space10">
        <div class="layui-col-md12">
          <input type="radio" name="voteTo" value="0" title="部门" lay-filter="dep">
          <input type="radio" name="voteTo" value="1" title="员工" lay-filter="emp" checked>
          <input type="radio" name="voteTo" value="2" title="其他" lay-filter="others">
        </div>
      </div>
    </div>
    <div class="layui-card-body">
      <form class="layui-form" action="" lay-filter="component-form-element">
        <div class="layui-row layui-col-space10 layui-form-item">
          <div class="layui-row layui-col-space10">
            <div class="layui-col-md12">
              <div class="layui-card layui-form" lay-filter="component-form-element" id="dep" style="display: none">
                <div class="layui-card-header">部门</div>
                <div class="layui-card-body layui-row layui-col-space10">
                  <div class="layui-col-md12">
                    <select name="dep" lay-verify="dep" id="deps">
                      <option value="4">销售部</option>

                    </select>
                  </div>
                </div>
              </div>
              <div class="layui-card layui-form" lay-filter="component-form-element" id="emp">
                <div class="layui-card-header">员工</div>
                <div class="layui-card-body layui-row">
                  <div class="layui-col-md12">
                    <select name="emp" lay-verify="emp" id="emps">
                        <option value="2019122402">张明哲</option>
                    </select>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="layui-form-item" style="margin-top: 20%;position: relative;left: 36.1%">
          <div class="layui-input-block"  >
            <button class="layui-btn" lay-submit lay-filter="component-form-element">提交</button>
          </div>
        </div>
      </form>
    </div>
  </div>

  
  <script src="../../../layuiadmin/layui/layui.js"></script>  
  <script>
  layui.config({
    base: '../../../layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'form'], function(){
    var $ = layui.$
    ,admin = layui.admin
    ,element = layui.element
    ,form = layui.form;

      //文档加载时加载部门信息
      $(function () {
          //加载部门信息
          $.ajax({
              url: "/dep/loadAll",
              data:{},
              dataType:"json",
              type:"post",
              success:function (res) {
                  var depList = res;

                  var str = "";
                  for(var i = 0;i < depList.length; i++){
                      var dep = depList[i];
                      str += "<option value='"+dep.depId+"'>"+dep.depName+"</option>";
                  }
                  $("#deps").html(str);
                  //必须重新加载
                  form.render();
              },
              error:function (e) {
                  console.log(e.responseText)
              }
          });
          //加载员工信息
          $.ajax({
              url: "/user/loadAll",
              data:{},
              dataType:"json",
              type:"post",
              success:function (res) {
                  var userList = res;
                  var str = "";
                  for(var i = 0;i < userList.length; i++){
                      var user = userList[i];
                      str += "<option value='"+user.userId+"'>"+user.userName+"</option>";
                  }
                  $("#emps").html(str);
                  //必须重新加载
                  form.render();
              },
              error:function (e) {
                  console.log(e.responseText)
              }
          });
      });
    //radio提交
    form.on('radio(dep)', function(data){
        $("#emp").hide();
        $("#dep").show();

     });

    form.on('radio(emp)', function(data){
        $("#dep").hide();
        $("#emp").show();
    });
      form.on('radio(others)', function(data){
          $("#dep").hide();
          $("#emp").hide();
      });
    //获取下拉框选择值
    form.on('select(dep)', function (data) {
       var dep = data.value;
       var  depName = data.elem[data.elem.selectedIndex].text;
          form.render('select');
     });
    form.on('select(emp)', function (data) {
          var emp = data.value;
          var empName = data.elem[data.elem.selectedIndex].text;
          form.render('select');
    });
    form.on('submit(component-form-element)', function(data){
        var id = "";
        var voteType = data.form.innerText.substr(0,2);
        if(voteType == "员工"){
             id = data.field.emp;
        }else if(voteType == "部门"){
            id = data.field.dep;
        }else{
            //其他测评
        }
        if(id != ""){
            window.location.href = '/user/goVoteType?voteType='+voteType+'&id='+id+'';
        }else{
            if(voteType == "提交"){
                window.location.href = '/user/goVoteType?voteType='+voteType+'&id='+id+'';
                return false;
            }else{
                layer.msg("请您选择测评对象");
            }

        }

         return false;
    });
  });
  </script>
</body>
</html>